package chapter02

import scala.math.BigDecimal.double2bigDecimal

/**
 * @program lu-scala01
 * @description:
 * @author: zhanglu
 * @create: 2022-02-11 16:25:00
 */
object C04_Grammar {

  def main(args: Array[String]): Unit = {
    //for循环学习
//    test01();
    //多层for学习
    test02();
  }

  def test01() : Unit = {
    for (i <- 1 to 3){
      print(i)
    }
    println()
    for (i <- 1 until 3){
      print(i)
    }
    println()
    for (i <- 1 to 3 if i != 2){
      print(i)
    }
    println()
    for (i <- 1 to 3 by 2){
      print(i)
    }
    println()
    for (i <- 1.0 to 2.0 by 0.3){
      print(i + " ")
    }
    println()
  }

  def test02() : Unit = {
    for (i <- 1 to 3; j <- 1 to 2; k <- 1 to 2){
      print(i + "-" + j + "-" + k + " ")
    }
    println()
    for (i <- 1 to 9; j <- 1 to i){
      print(s"$i * $j = ${i * j}\t")
      if(j == i){
        println()
      }
    }
    println()
    for (i <- 1 to 4; j = 4 - i){
      print(s"i=$i j=$j \t")
    }
    println()
    for {
        i <- 1 to 4
        j = 4 - i
    } {
      print(s"i=$i j=$j \t")
    }
    println()
    for (start <- 1 to 17 by 2; end = (17 - start) / 2){
      println(" " * end + "*" * start)
    }
    println()
  }

}
